package test;

import java.util.HashMap;
import java.util.Map;

import main.DataConnection;
import main.Its;
import main.ItsChooser;
import main.ResultSet;

public class ItsTester {
	
	public Its[] generateIts(){
		Its itsList[] = new Its[4];
		itsList[0] = new Its("tram plus");
		itsList[1] = new Its("adapt ligths");
		itsList[2] = new Its("bus lane");
		itsList[3] = new Its("radar");
		
		itsList[0].addProblem("emission");
		itsList[0].addProblem("noise");
		itsList[1].addProblem("emission");
		itsList[2].addProblem("emission");
		itsList[3].addProblem("emission");
		
		itsList[0].addSubProblem("emission", "cars", 0.4);
		itsList[0].addSubProblem("emission", "buses", 0.2);
		itsList[0].addSubProblem("noise", "cars", 0.4);
		itsList[1].addSubProblem("emission", "cars", 0.4);
		itsList[2].addSubProblem("emission", "trams", 0.4);
		itsList[3].addSubProblem("emission", "buses", 0.4);
		
//		for(int i=0; i<itsList.length; i++){
//			System.out.print("Its no." +i+ "- ");
//			System.out.print(itsList[i]);
//		}
		
		itsList[0].removeProblem("noise");
		itsList[0].removeProblem("dumb");
		itsList[0].remSubProblem("emission", "buses");
		itsList[1].addSubProblem("emission", "boats", 0.01);
		itsList[2].updateSubProblem("emission", "trams", 1.0);
		
		for(int i=0; i<itsList.length; i++){
			System.out.print("Its no." +i+ "- ");
			System.out.println(itsList[i]);
		}
		
		return itsList;	
	}
	
	public void printItsList(Its[] itsList){
		String result = "";
		for(int i=0; i<itsList.length; i++){
			result += "Its no." +i+ "- ";
			result += itsList[i];
		}	
		System.out.println(result);
	}
	
	public String printIntTab(int[] tab){
		String result = "";
		for(int i : tab){
			result += i + " ";
		}
		return result;
	}
	
	public static void main(String[] args){
//		ItsTester tester = new ItsTester();
//		Its itsList[] = tester.generateIts();
		Its itsList[] = DataConnection.readData();
//		tester.printItsList(itsList);		
		ItsChooser itc = new ItsChooser(itsList);
		
		Map<String, Double> problems = new HashMap<String, Double>();
		problems.put("emission", 0.7);
		ResultSet results = itc.getResults(problems, 2012);
//		System.out.println("reults: " + results);
		results.sort(problems, ResultSet.BY_EFFICIENCY);
		System.out.println("Sorted reults: " + results);
		
	}
}
